public class MinSubArrayLen {
    public int code(int target, int[] nums) {
        int sum = 0, ret = Integer.MAX_VALUE;
        for (int left = 0, right = 0; right < nums.length; right++){
            sum += nums[right];

            while (sum >= target){
                ret = Math.min(ret, right - left + 1);
                sum -= nums[left];
                left++;
            }
        }

        return ret == Integer.MAX_VALUE?0:ret;
    }
}
